package com.canoe;

import com.canoe.common.CanoeException;
import com.canoe.common.FirstLevelOrder;

import java.util.Arrays;
import java.util.Objects;

/**
 * 命令解析执行器
 *
 * @author: btm
 * @time: 14:41 2020/9/24
 **/
public final class OrderParserHandler {

    /**
     * 一级指令适配器
     */
    private static final FirstLevelOrderAdapter FIRST_LEVEL_ORDER_ADAPTER = new FirstLevelOrderAdapter();

    public static void doParserAndHandler(String... args) {
        if (Objects.isNull(args)|| args.length<=0) {
            throw new CanoeException("need parameter");
        }
        String orderTargetTypeName = args[0];
        FirstLevelOrder firstLevelOrder = FirstLevelOrder.findByOrderName(orderTargetTypeName);
        FIRST_LEVEL_ORDER_ADAPTER.getProcessor(firstLevelOrder).process(Arrays.copyOfRange(args,1,args.length));
    }

}
